package controller.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.dao.UserInfoDAO;
import model.domain.UserInfoBean;
import model.domain.UserInfomationBeans;

public class LoginAction implements Action {
	@Override
	public String process(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// DB id check!!!!
		
		String userid=request.getHeader("userid");
		String userpw=request.getHeader("userpw");
		System.out.println(userid+"     "+userpw);
		List<UserInfoBean> alldata=UserInfoDAO.selectAllUserId();
		response.setHeader("command", "login");
		for(int i=0; i<alldata.size(); i++){
			if(userid.equals((alldata.get(i)).getUserId())&& userpw.equals(alldata.get(i).getUserPass())){
				request.getSession().setAttribute("login", userid);
				response.setHeader("userid", userid);
				return "checked";
			}
		}
		return null;
		
		
		/*response.setHeader("command", "login");
		if (request.getHeader("userid").equals("test")) {
			if (request.getHeader("userpw").equals("test")) {
				request.getSession().setAttribute("userid", "test");
				response.setHeader("userid", "test");
				return "checked";
			} else {
				return "wrong pw";
			}
		} else {
			return "invalid id";
		}*/
		// Add Session Attribute
	}
}
